package com.springsecirtytest.activiti1.security;

import com.springsecirtytest.activiti1.mapper.UserInfoBeanMapper;
import com.springsecirtytest.activiti1.pojo.UserInfoBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

@Component
public class MyUserDetailsSetvice implements UserDetailsService {
    @Autowired
    UserInfoBeanMapper userInfoBeanMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {


        UserInfoBean userInfoBean =userInfoBeanMapper.selectByUserName(username);
        if (userInfoBean==null){
            throw new  UsernameNotFoundException("找不到用户");
        }
        return  userInfoBean;
    }

    @Bean
    public PasswordEncoder passwordEncoder(){
        return new BCryptPasswordEncoder();
    }
}
